'use strict';

var routes = [{
    path: '/',
    name: "index",
    component: indexPage,
    children: [{
        path: '/details',
        name: "details",
        component: detailsPage,
        children: [{
            path: '/details/peopleList',
            name: "peopleList",
            component: peopleListWrap
        }, {
            path: '/details/feedBackDetail',
            name: "feedBackDetail",
            component: feedBackDetailPage
        }]
    }, {
        path: '/news',
        name: "news",
        component: newsDetails,
        children: [{
            path: '/news/newsAdd',
            name: "newsAdd",
            component: addNewsListWrap
        }, {
            path: '/news/newsDetails_info',
            name: "newsDetails_info",
            component: infoDetailPage
        }, {
            path: '/news/peopleList',
            name: "newsPeopleList",
            component: peopleListWrap
        }]
    }]
}];

var router = new VueRouter({
    routes: routes
});

var store = new Vuex.Store({
    state: {
        showFlag: 0,
        roleRank: 0,
        headerAnimate: "",
        title: "",
        headerType: 0,
        peopleList: false,
        loadingShow: false
    },
    mutations: {
        _showFlag: function _showFlag(state, val) {
            state.showFlag = val;
        },
        _headerAnimate: function _headerAnimate(state, val) {
            state.headerAnimate = val;
        },
        _title: function _title(state, val) {
            state.title = val;
        },
        _headerType: function _headerType(state, val) {
            state.headerType = val;
        },
        _peopleList: function _peopleList(state, val) {
            state.peopleList = val;
        },
        _loadingShow: function _loadingShow(state, val) {
            state.loadingShow = val;
        },
        _roleRank: function _roleRank(state, val) {
            state.roleRank = val;
        }
    },
    getters: {
        //改变头部文字
        showFlag_get: function showFlag_get(state) {
            state.title = getHeader.init(state.showFlag);
            return state.showFlag;
        },
        headerAnimate_get: function headerAnimate_get(state) {
            return state.headerAnimate;
        }
    },
    actions: {
        showFlag_action: function showFlag_action(context, val) {
            context.commit("_showFlag", val);
        },
        headerAnimate_action: function headerAnimate_action(context, val) {
            if (val) {
                context.commit("_headerAnimate", "header-back");
            } else {
                context.commit("_headerAnimate", "header-forward");
            }
            setTimeout(function () {
                context.commit("_headerAnimate", "");
            }, 500);
        }
    }
});

var APP = new Vue({
    router: router,
    store: store
});

function goBack(index) {
    if (isPush.flag && (store.state.showFlag.toString() === "12" || store.state.showFlag.toString() === "2")) {
        vrvInit.closeWindow();
        return;
    }
    index = index || -1;
    store.dispatch("headerAnimate_action", 1);
    window.history.go(index);
}

function headerTitleChange(v) {
    store.dispatch("headerAnimate_action", 0);
    store.dispatch("showFlag_action", v);
}

function goName(name, flag) {
    flag && headerTitleChange(flag);
    router.push({ name: name });
}

function goPathWithParams(path, flag) {
    flag && headerTitleChange(flag);
    router.push({ path: path });
}